import { Component,ViewChild } from '@angular/core';
import { NavController,AlertController,Content } from 'ionic-angular';

import { HTTP } from '@ionic-native/http';

import {IndexPage} from "../index/index";//传的数据

import   $  from 'jquery';

@Component({
  selector: 'page-jilu',
  templateUrl: 'jilu.html'
})
export class JiluPage {
    
    @ViewChild(Content) content:Content;
    
    huabi={
      "shou":"添加地址"
    }
    dingName:string;   //姓名
    dingIphone:string; //电话
    dingBian:string; //邮编
    dingDi:string; //地址
    dingXiang:string; //详细地址
    dingId:number;
    userid=localStorage.getItem("userid");
    public url:string ="http://118.31.79.20:8080/";  //服务器
    //  public url:string ="http://192.168.1.114:8080/";  //本地
     public shop_url:string =this.url + "Stock/order/findOrderList.do";  //订单接口
     public wu_url:string= this.url + "Stock/address/updateAddress.do"; //物流接口
     public cha_url:string= this.url + "Stock/address/findAddressById.do";//查询接口
     public data_lists:Array<any>=[];
    constructor(public navCtrl: NavController,private http: HTTP,private malert:AlertController,) {
        
    }
  ionViewDidLoad(){
    

  }
  ionViewDidEnter(){
    // console.log('开始执行');
    // console.log('内容高'+this.content.contentHeight);
    //  console.log("遮盖曾" +$('#screen').height());
    this.HAHA();
   
  }

  HAHA(){
     if(this.userid==''||this.userid==null){
       
      this.mWind("您好，您没有登录账户信息！！");
       this.navCtrl.push(IndexPage);
    }else{
   
      this.http.post(this.shop_url, {"uid": this.userid}, {})
        .then(data => {
          //获取的数据
           var data_Da=JSON.parse(data.data);
        //   数据
            var data_roots=data_Da.currentPageDatas;
             
            // alert(data_roots);
            for(var  k in data_roots){
           
                 this.data_lists.push(data_roots[k]);
                
            }
            $(".scrizz").css("display","none");
        })
         .catch(error => {
      
             this.mWind(error);
      
        });
    }
  }
  
// 提交信息
  can(i){
    console.log(11);
    $(".scrizz").css("display","block");
    
      //  alert(i); 
      //  alert(this.data_lists[i].id);
      this.dingId = this.data_lists[i].id;
    // var id = localStorage.setItem("DingId",this.data_lists[i].id);
       if(this.data_lists[i].isYNA == "修改地址"){
       
          this.dingName = this.data_lists[i].shouhuoren;
          this.dingIphone =this.data_lists[i].mobile;
          this.dingBian = this.data_lists[i].youbian;
          this.dingDi = this.data_lists[i].address;
          this.dingXiang = this.data_lists[i].area;
                    
       }else if(this.data_lists[i].isYNA == "填写地址"){
             this.dingName = this.data_lists[i].shouhuoren;
             this.dingIphone =this.data_lists[i].mobile;
             this.dingBian = this.data_lists[i].youbian;
             this.dingDi = this.data_lists[i].address;
             this.dingXiang = this.data_lists[i].area;
       }
  }


  // 点击保存
  bao(){
        
        
        if(this.dingName =='' || this.dingName ==null ){
      
           this.mWind('姓名不能为空');
        }else if(this.dingIphone =='' || this.dingIphone ==null){
          this.mWind('电话不能为空');
       
        }else if(this.dingBian ==''|| this.dingBian ==null){
           this.mWind('编码不能为空');
         
        }else if(this.dingDi =='' || this.dingDi ==null){
           this.mWind('地区不能为空');
        
        }else if(this.dingXiang =='' || this.dingXiang ==null){
           this.mWind('详细地址不能为空');
        }else{
             this.http.post(this.wu_url, {"uid": this.userid,'id':this.dingId,'shouhuoren':this.dingName,'mobile': this.dingIphone,'youbian': this.dingBian,'address': this.dingDi,'area':this.dingXiang}, {})
            .then(data => {
              var data_r = JSON.parse(data.data);
              if(data_r.flag == true){
                  this.mWind("地址保存成功");
                 
                  this.HAHA();
          
              }else{
                
                this.mWind("地址保存失败");
              }
            
            })
            .catch(error => {
          

            });
        }

       
  }  
 /**
    * 自定义弹框
    */
    mWind(msg){
        let alert= this.malert.create({
      title :"提示",
      message:msg,
      buttons:[{
        text:'取消',
        handler:()=>{         
        }
      },{
        text:'确定',
        handler:()=>{       
        }
      }],
      
    });
  alert.present();

    }
    /**
     * 无按钮
     * @param msg 
     */
    mWinds(msg){
            let alert= this.malert.create({
          title :"提示",
          message:msg,     
        });
      alert.present();

    }

  
}
